import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/manage',
    name: 'Manage',
    component: () => import('@/views/manage/index'),
    hidden: true
  },
  {
    path: '/home',
    component: Layout,
    redirect: '/home/notice',
    meta: { title: '首页管理', icon: 'el-icon-s-home' },
    children: [
      {
        path: 'notice',
        name: 'Notice',
        component: () => import('@/views/home/notice/index.vue'),
        meta: { title: '公告', icon: 'el-icon-bell' }
      },
      {
        path: 'banner',
        name: 'Banner',
        component: () => import('@/views/home/banner/index.vue'),
        meta: { title: '宣传', icon: 'el-icon-money' }
      }
    ]
  },
  {
    path: '/short',
    component: Layout,
    redirect: '/short/category',
    meta: { title: '短剧管理', icon: 'el-icon-video-camera-solid' },
    children: [
      {
        path: 'category',
        name: 'Category',
        component: () => import('@/views/short/category/index.vue'),
        meta: { title: '分类', icon: 'el-icon-s-help' }
      },
      {
        path: 'short',
        name: 'Short',
        component: () => import('@/views/short/short/index.vue'),
        meta: { title: '短剧', icon: 'el-icon-s-platform' },
        props(route) {
          return {
            id: route.query.id
          }
        }
      },
      {
        path: 'episode',
        name: 'Episode',
        component: () => import('@/views/short/episode/index.vue'),
        hidden: true,
        meta: { title: '剧集', icon: 'dashboard', activeMenu: '/short/short' },
        props(route) {
          return {
            id: route.query.id
          }
        }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/user',
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/user/user/index.vue'),
        meta: { title: '用户', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    path: '/actor',
    component: Layout,
    redirect: '/actor/actor',
    meta: { title: '演员管理', icon: 'dashboard' },
    children: [
      {
        path: 'actor',
        name: 'Actor',
        component: () => import('@/views/actor/actor/index.vue'),
        meta: { title: '演员', icon: 'el-icon-s-custom' }
      },
      {
        path: 'opus',
        name: 'Opus',
        component: () => import('@/views/actor/opus/index.vue'),
        hidden: true,
        meta: { title: '作品', icon: 'dashboard', activeMenu: '/actor/actor' },
        props: (route) => {
          return {
            id: route.query.id
          }
        }
      },
      {
        path: 'schedules',
        name: 'Schedules',
        component: () => import('@/views/actor/schedules/index.vue'),
        hidden: true,
        meta: { title: '排期', icon: 'dashboard', activeMenu: '/actor/actor' },
        props: (route) => {
          return {
            id: route.query.id
          }
        }
      }
    ]
  },
  {
    path: '/show',
    component: Layout,
    redirect: '/show/show',
    meta: { title: '剧场管理', icon: 'dashboard' },
    children: [
      {
        path: 'show',
        name: 'Show',
        component: () => import('@/views/show/show/index.vue'),
        meta: { title: '剧场', icon: 'el-icon-video-camera' }
      },
      {
        path: 'scene',
        name: 'Scene',
        component: () => import('@/views/show/scene/index.vue'),
        meta: { title: '场次', icon: 'dashboard', activeMenu: '/show/show' },
        hidden: true,
        props(route) {
          return {
            showId: route.query.showId
          }
        }
      },
      {
        path: 'seat',
        name: 'Seat',
        component: () => import('@/views/show/seat/index.vue'),
        meta: { title: '座位', icon: 'dashboard', activeMenu: '/show/show' },
        hidden: true,
        props(route) {
          return {
            showSceneId: route.query.showSceneId
          }
        }
      }
    ]
  },
  {
    path: '/drama',
    component: Layout,
    redirect: '/drama/drama',
    meta: { title: '大戏管理', icon: 'dashboard' },
    children: [
      {
        path: 'drama',
        name: 'Drama',
        component: () => import('@/views/drama/drama/index.vue'),
        meta: { title: '大戏', icon: 'el-icon-film' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '数据大屏', icon: 'el-icon-s-marketing' }
    }]
  }
]

export const asyncRoutes = [
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
